using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using SFS.SampleApp.Web.Mvc.Resources;
using System.Runtime.Serialization;
using SFSdotNet.Framework.Web.Mvc.Models;
using SFSdotNet.Framework.Web.Mvc.Extensions;
using BO = SFS.SampleApp.BusinessObjects;
using System.Web.Mvc;
using SFSdotNet.Framework.Web.Mvc.Validation;
using SFSdotNet.Framework.Web.Mvc.Models;
using SFSdotNet.Framework.Web.Mvc.Resources;
using SFSdotNet.Framework.Entities.Metadata;


namespace SFS.SampleApp.Web.Mvc.Models.ProductCategories 
{
	public partial class ProductCategoryModel: ModelBase{
		public ProductCategoryModel()
        {
		}
		public override string Id
        {
            get
            {
                return this.ProductCategoryID.ToString();
            }
        }
			
			
        public override string ToString()
        {
		
            return this.Name.ToString();
		
        }    
			
	
		[SystemProperty()]		
		public Int32? ProductCategoryID{ get; set; }
		
	
[Exportable()]
	
	    [Required(AllowEmptyStrings=false, ErrorMessageResourceName="VAL_NAME_REQUIRED", ErrorMessageResourceType=typeof(ProductCategoryResources))]
		
	[RelationFilterable()]
	[LocalizedDisplayName("NAME", NameResourceType=typeof(ProductCategoryResources))]
	public String   Name { get; set; }
		
		
	
[Exportable()]
		
	[RelationFilterable()]
	[SystemProperty()]
	[LocalizedDisplayName("ROWGUID", NameResourceType=typeof(ProductCategoryResources))]
	public Guid   rowguid { get; set; }
		
		
	
[Exportable()]
	
	    [Required(AllowEmptyStrings=false, ErrorMessageResourceName="VAL_MODIFIEDDATE_REQUIRED", ErrorMessageResourceType=typeof(ProductCategoryResources))]
		
	[RelationFilterable()]
	[DateTime(true, false, null)]	
	[LocalizedDisplayName("MODIFIEDDATE", NameResourceType=typeof(ProductCategoryResources))]
	public DateTime   ModifiedDate { get; set; }
	public string ModifiedDateText {
        get {
            if (ModifiedDate != null)
			
                return ((DateTime)ModifiedDate).ToShortDateString();
            else
                return String.Empty;
        }
				set{
				this.ModifiedDate = Convert.ToDateTime(value);
    }
		}
		
		
	
[Exportable()]
		
	[RelationFilterable(DataClassProvider = typeof(Controllers.ProductCategoriesController), GetByKeyMethod="GetByKey", GetAllMethod = "GetAll", DataPropertyText = "Name", DataPropertyValue = "ProductCategoryID", FiltrablePropertyPathName="ProductCategory2.ProductCategoryID")]	

	[LocalizedDisplayName("PRODUCTCATEGORY2", NameResourceType=typeof(ProductCategoryResources))]
	public Int32  ? FkProductCategory2 { get; set; }
		[LocalizedDisplayName("PRODUCTCATEGORY2", NameResourceType=typeof(ProductCategoryResources))]
	[Exportable()]
	public string  FkProductCategory2Text { get; set; }
    public string FKProductCategory2SafeKey { get; set; }

	
		
		
		[LocalizedDisplayName("PRODUCTS", NameResourceType=typeof(ProductCategoryResources))]
		[RelationFilterable(IsNavigationPropertyMany=true, FiltrablePropertyPathName="Products.Count()", ModelPartialType="Products.Product")]
        public List<Products.ProductModel> Products { get; set; }			
	
		[LocalizedDisplayName("PRODUCTCATEGORY1", NameResourceType=typeof(ProductCategoryResources))]
		[RelationFilterable(IsNavigationPropertyMany=true, FiltrablePropertyPathName="ProductCategory1.Count()", ModelPartialType="ProductCategories.ProductCategory")]
        public List<ProductCategories.ProductCategoryModel> ProductCategory1 { get; set; }			
	
	public override string SafeKey
   	{
		get
        {
			if(this.ProductCategoryID != null)
				return SFSdotNet.Framework.Entities.Utils.GetKey(this ,"ProductCategoryID").Replace("/","-");
			else
				return String.Empty;
		}
    }		
		public void Bind(ProductCategoryModel model){
            
		this.ProductCategoryID = model.ProductCategoryID;
		this.Name = model.Name;
		this.rowguid = model.rowguid;
		this.ModifiedDate = model.ModifiedDate;
        }

        public BusinessObjects.ProductCategory GetBusinessObject()
        {
            BusinessObjects.ProductCategory result = new BusinessObjects.ProductCategory();
	if (this.ProductCategoryID != null )
				result.ProductCategoryID = (Int32)this.ProductCategoryID;
				
	if (this.Name != null )
				result.Name = (String)this.Name.Trim().Replace("\t", String.Empty);
				
	if (this.rowguid != null )
				result.rowguid = (Guid)this.rowguid;
				
				result.ModifiedDate = (DateTime)this.ModifiedDate;		
				
			
			if(this.FkProductCategory2 != null )
	result.ProductCategory2 = new BusinessObjects.ProductCategory() { ProductCategoryID= (Int32)this.FkProductCategory2 };
				



            return result;
        }
        public void Bind(BusinessObjects.ProductCategory businessObject)
        {
            
			this.ProductCategoryID = businessObject.ProductCategoryID;
				
			this.Name = businessObject.Name != null ? businessObject.Name.Trim().Replace("\t", String.Empty) : "";
				
			this.rowguid = businessObject.rowguid;
				
				this.ModifiedDate = (DateTime)businessObject.ModifiedDate;
	        if (businessObject.ProductCategory2 != null){
	                	this.FkProductCategory2Text = businessObject.ProductCategory2.Name.Trim().Replace("\t", String.Empty); 
										
										
				this.FkProductCategory2 = businessObject.ProductCategory2.ProductCategoryID;
                this.FKProductCategory2SafeKey  = SFSdotNet.Framework.Entities.Utils.GetKey(businessObject.ProductCategory2,"ProductCategoryID").Replace("/","-");

			}
           
        }
	}
}
